using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Trippy.Animation;
using Trippy.CollidableGameComponents.Agents;
using Trippy.CollidableGameComponents.Objects;
using Trippy.Levels;


namespace Trippy.CollidableGameComponents.Projectiles
{
    class EnemyFireball : CollidableGameComponent
    {
        public static Texture2D SpriteSheet { get; private set; }
        float timer = 15f;

        public EnemyFireball(Level level)
            : base(level)
        {
            if (SpriteSheet == null) SpriteSheet = CurrentLevel.Game.Content.Load<Texture2D>("Sprites/Projectiles/fireball");
            Sprite = new AnimatedSprite(this, SpriteSheet, SpriteSheet.Height, SpriteSheet.Width, 0, 0, 0, 0, 1, 0f);
            Friction = 0.0f;
        }
        
        public override void Update(GameTime gameTime)
        {
            timer -= TrippyUtilities.CalculateElapsedTime(gameTime);
            if (timer <= 0)
            {
                new EffectAnimation(CurrentLevel, EffectAnimation.Effects.Explosion, Position);
                MarkForDeletion();
            }
            UpdateStandardPhysics(TrippyUtilities.CalculateElapsedTime(gameTime));
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            StandardDraw(gameTime);
            base.Draw(gameTime);
        }

        protected override void CollisionHandler(CollidableGameComponent component, CollidableGameComponent.CollisionSide side)
        {
            if (component is Hero)
            {
                Hero h = (Hero)component;
                h.Die(Hero.MannerOfDeath.Enemy);
                new EffectAnimation(CurrentLevel, EffectAnimation.Effects.Explosion, Position);
                MarkForDeletion();
            }

            base.CollisionHandler(component, side);
        }

        public override void Restore()
        {
            base.Restore();
            MarkForDeletion();
        }
    }
}
